package com.dog.basics.sys.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.dog.basics.bean.dto.admin.sys.DictTypeAddDto;
import com.dog.basics.bean.dto.admin.sys.DictTypeEditDto;
import com.dog.basics.bean.vo.admin.sys.DictTypeInfoVo;
import com.dog.basics.bean.vo.admin.sys.DictTypePageVo;
import com.dog.basics.common.annotation.SysLog;
import com.dog.basics.common.constant.SwaggerConstants;
import com.dog.basics.common.util.PageParam;
import com.dog.basics.common.util.R;
import com.dog.basics.service.sys.IDictTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 字典类型表 前端控制器
 * </p>
 *
 * @author guoy
 * @since 2020-03-27
 */
@RestController
@RequestMapping("/sys/dict-type")
@Api(value = SwaggerConstants.SYSTEM+ "字典类型", tags = SwaggerConstants.SYSTEM+"字典类型模块")
@AllArgsConstructor
@ApiIgnore
public class DictTypeController {
    private final IDictTypeService dictTypeService;
    /**
     * @Description:  分页字典类型列表
     * @Param:  phone
     * @return:  IPage<AppVersionPageVo>
     * @Author: wph
     * @Date: 2020/3/27 0027
     */
    @ApiOperation(value = "分页字典类型列表", notes = "pc:dict-type:page")
    @GetMapping("/page")
    @PreAuthorize("@pms.hasPermission('pc:dict-type:page')")
    public R<IPage<DictTypePageVo>> page(PageParam page) {
        IPage<DictTypePageVo> advicePageDto = dictTypeService.getPageList(page);
        return R.ok(advicePageDto);
    }

    /**
     * @Description:  增加字典类型
     * @Param:  appVersionAddDto
     * @return:  Boolean
     * @Author: wph
     * @Date: 2020/3/27 0027
     */
    @SysLog("增加字典类型")
    @ApiOperation(value = "增加字典类型", notes = "pc:dict-type:save")
    @PostMapping("/save")
    @PreAuthorize("@pms.hasPermission('pc:dict-type:save')")
    public R<Boolean> save(@Valid @RequestBody DictTypeAddDto dictTypeAddDto) {
        dictTypeService.saveObj(dictTypeAddDto);
        return R.ok();
    }

    /**
     * @Description:  删除字典类型
     * @Param:  ids
     * @return:  Boolean
     * @Author: wph
     * @Date: 2020/3/27 0027
     */
    @SysLog("删除字典类型")
    @ApiOperation(value = "删除字典类型", notes = "pc:dict-type:delete")
    @ApiImplicitParam(value = "字典类型Id", name = "ids", dataType = "List<Long>", required = true)
    @DeleteMapping("/delete")
    @PreAuthorize("@pms.hasPermission('pc:dict-type:delete')")
    public R<Boolean> delete(@RequestParam(value = "ids") List<Long> ids) {
        dictTypeService.deleteObj(ids);
        return R.ok();
    }

    /**
     * @Description:  修改字典类型
     * @Param:  appVersionEditDto
     * @return:  Boolean
     * @Author: wph
     * @Date: 2020/3/27 0027
     */
    @SysLog("修改字典类型")
    @ApiOperation(value = "修改字典类型", notes = "pc:dict-type:edit")
    @PutMapping("/edit")
    @PreAuthorize("@pms.hasPermission('pc:dict-type:edit')")
    public R<Boolean> edit(@Valid @RequestBody DictTypeEditDto ictTypeEditVo) {
        dictTypeService.editObj(ictTypeEditVo);
        return R.ok();
    }

    /**
     * @Description:  查看字典类型
     * @Param:  id
     * @return:  AppVersionInfoVo
     * @Author: wph
     * @Date: 2020/3/27 0027
     */
    @SysLog("查看字典类型")
    @ApiOperation(value = "查看字典类型", notes = "pc:dict-type:info")
    @ApiImplicitParam(value = "id", name = "id", dataType = "Long", required = true)
    @GetMapping("/info/{id}")
    @PreAuthorize("@pms.hasPermission('pc:dict-type:info')")
    public R<DictTypeInfoVo> info(@PathVariable("id") Long id) {

        return R.ok(dictTypeService.info(id));
    }

}
